package com.crm.controller;

import com.crm.controller.util.R;
import com.crm.pojo.Cservice;
import com.crm.service.serviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/service")
public class serviceController {
    @Autowired
    private serviceService service1;

    @GetMapping
    public R queryAll(){
        List<Cservice> list = service1.selectAll();
        return new R(true,list,true? "查询成功":"查询失败");
    }
    @GetMapping("/{id}")
    public R queryOne(@PathVariable int id){
        Cservice service = service1.selectOne(id);
        return new R(true,service,true? "查询成功":"查询失败");
    }
    @PostMapping
    public R save(@RequestBody Cservice service){
        System.out.println(service);
        boolean flag = service1.save(service);
        return new R(flag,null,flag? "添加成功":"添加失败");
    }
    @PutMapping
    public R update(@RequestBody Cservice service){
        boolean flag = service1.update(service);
        return new R(flag,null,flag? "修改成功":"修改失败");
    }
    @DeleteMapping("/{id}")
    public R removeOne(@PathVariable int id){
        boolean flag = service1.remove(id);
        return new R(flag,null,flag? "删除成功":"删除失败");
    }
}
